{% extends 'layout.html' %}
{% load static %}
{% load permission %}

{% block content %}
    <div style="margin-bottom: 5px" class="clearfix">
        {% add_permission request 'user_add' %}
        {% if search_group.get_row_list %}
            {% include 'include/search_group.html' %}
        {% endif %}
        <div class="right">
            {# 用form表单提交   #}
            <form class="form-inline" method="get">
                <div class="form-group">
                    <label for="searchBox">搜索</label>
                    <input id="searchBox" name="keyword" type="text" class="form-control"
                           placeholder="请输入关键字" value="{{ keyword }}">
                </div>
                <button type="submit" class="btn btn-default">
                    {# 放大镜图标 #}
                    <span class="glyphicon glyphicon-search"></span>
                </button>
            </form>
        </div>
    </div>

    <table class="table table-bordered">
        <thead>
        <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>手机号</th>
            <th>账户余额</th>
            <th>级别</th>
            <th>注册时间</th>
            <th>创建者</th>
            <th>交易记录</th>
            <th>重置密码</th>
            {% if request|has_permission:"user_edit.user_delete" %}
                <th>操作</th>
            {% endif %}
        </tr>
        </thead>
        <tbody>
        {% for row in queryset %}
            <tr>
                <td>{{ row.id }}</td>
                <td>{{ row.username }}</td>
                <td>{{ row.mobile }}</td>
                <td>{{ row.balance }}</td>
                <td>{{ row.level }} ({{ row.level.discount }}%)</td>
                {# 处理时间格式 #}
                <td>{{ row.create_date|date:'Y-m-d H:i:s' }}</td>
                <td>{{ row.createdBy.username }}</td>
                <td><a href="{% url 'user_charge' pk=row.id %}" class="btn btn-primary btn-xs">交易记录</a></td>
                <td><a href="{% url 'user_reset' pk=row.id %}" class="btn btn-primary btn-xs">重置密码</a></td>
                {% if request|has_permission:"user_edit.user_delete" %}
                    <td>
                        {% edit_permission request 'user_edit' pk=row.id %}
                        {# 自定义属性cid为当前数据的的id为了方便接下来的操作 #}
                        {# <a cid="{{ row.id }}" class="btn btn-danger btn-xs btn-delete">删除</a> #}
                        {% delete_permission request 'user_delete' row.id %}
                    </td>
                {% endif %}

            </tr>
        {% endfor %}

        </tbody>
    </table>

    {% include 'include/delete_modal.html' %}
    <ul class="pagination">
        {{ page_string }}
    </ul>

{% endblock %}
{% block js %}

    <script>
        var DELETE_ID;
        var DELETE_URL = "{% url 'user_delete' %}";
    </script>
    <script src="{% static 'js/delete_modal.js' %}"></script>
{% endblock %}